{include file='/public/header'}

<div class="am-cf admin-main">
    {include file='/public/sidebar'}

    <!-- content start -->
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">文章管理</strong> / <small>文章列表</small></div>
            </div>

            <hr>

            <div class="am-g">
                <!--<form class="am-form" action="{:url('/admin/article/index')}" method="get">-->
                <!--<div class="am-u-sm-12 am-u-md-4">-->
                    <!--<div class="am-btn-toolbar">-->
                        <!--<div class="am-btn-group am-btn-group-xs">-->
                            <!--<a href="{:url('admin/article/add_new')}" class="am-btn am-btn-default"><span class="am-icon-plus"></span> 新增文章</a>-->
                        <!--</div>-->
                    <!--</div>-->
                <!--</div>-->
                <!--<div class="am-u-sm-12 am-u-md-5">-->
                    <!--<div class="am-form-group">-->
                        <!--<select id="top_categories" name="category_id" data-am-selected="{btnWidth:'38%',btnSize:'md'}">-->
                            <!--<option value="0">选择分类</option>-->
                            <!--{foreach $top_categories as $category}-->
                            <!--<option value="{$category.id}" {if($selected_top_category['id'] == $category['id'])}selected="selected"{/if}>{$category.name}</option>-->
                            <!--{/foreach}-->
                        <!--</select>-->
                    <!--</div>-->
                <!--</div>-->
                <!--<div class="am-u-sm-12 am-u-md-3">-->
                    <!--<div class="am-input-group am-input-group-sm">-->
                        <!--<input type="text" class="am-form-field" name="title" value="{$title}">-->
                        <!--<span class="am-input-group-btn"><button type="submit" class="am-btn am-btn-default" type="button">搜索</button></span>-->
                    <!--</div>-->
                <!--</div>-->
                <!--</form>-->
                <form class="am-form-inline" role="form">
                    <div class="am-u-sm-12 am-u-md-5">
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">
                                <a href="{:url('admin/article/add_new')}" class="am-btn am-btn-default"><span class="am-icon-plus"></span> 新增文章</a>
                            </div>
                        </div>
                    </div>

                    <div class="am-u-sm-12 am-u-md-7">
                        <div class="am-form-group">
                            <select id="top_categories" name="category_id" data-am-selected="{btnWidth:'100%',btnSize:'md'}">
                                <option value="0">全部分类</option>
                                {foreach $top_categories as $category}
                                <option value="{$category.id}" {if($selected_top_category['id'] == $category['id'])}selected="selected"{/if}>{$category.name}</option>
                                {/foreach}
                            </select>
                        </div>
                        <div class="am-form-group am-input-group-sm">
                            <input type="text" class="am-form-field" name="doc_name" value="{$doc_name}" placeholder="文档名称，支持模糊" />
                        </div>
                        <div class="am-input-group am-input-group-sm">
                            <input type="text" class="am-form-field" name="title" value="{$title}" placeholder="文章标题，支持模糊">
                            <span class="am-input-group-btn"><button type="submit" class="am-btn am-btn-default" type="button">搜索</button></span>
                        </div>
                    </div>
                </form>
            </div>

            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-check"><input type="checkbox" /></th>
                                <th class="table-id">ID</th>
                                <th class="table-title">标题</th>
                                <th class="table-type">所属文档</th>
                                <th class="table-type">所属分类</th>
                                <th class="table-date am-hide-sm-only">发布日期</th>
                                <th class="table-date am-hide-sm-only">发布状态</th>
                                <th class="table-set">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo" key="k"}
                            <tr>
                                <td><input type="checkbox" /></td>
                                <td>{$k}</td>
                                <td><a href="#">{$vo.title}</a></td>
                                <td>{:getDocNameById($vo['doc_id'])}</td>
                                <td>{:getCategoryNameById($vo['category_id'])}</td>
                                <td class="am-hide-sm-only">{$vo['create_time']}</td>
                                <td>{if($vo['is_publish'])}已发布{else}<font color="red">未发布</font>{/if}</td>
                                <td>
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs">
                                            <button type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="location.href='{:url('admin/article/edit_new',['id'=>$vo['id']])}'"><span class="am-icon-pencil-square-o"></span> 编辑</button>
                                            <!--<button type="button" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" ajax-del="{:url('admin/article/del',['id'=>$vo['id']])}"><span class="am-icon-trash-o"></span> 删除</button>-->
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                        <div class="am-cf">
                            共 {$total} 条记录
                            <div class="am-fr">
                                {$page|raw}
                            </div>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>
    <!-- content end -->
</div>

{include file='/public/footer'}
<script>
    $(document).ready(function() {
        $('#top_categories').on('change', function (e) {
            $('#sec_categories').empty();
            var top_category_id = $(this).val();
            var url = "{:url('admin/category/ajax_get_sec_categories')}";
            var data = {top_category_id: top_category_id};
            $.ajax({
                url: url,
                data: data,
                success: function (res) {
                    if (res.code == 1) {
                        var resultData = res.data;
                        for (key in resultData) {
                            $('#sec_categories').append('<option value="' + resultData[key]['id'] + '">' + resultData[key]['name'] + '</option>');
                        }
                    }
                },
                error: function (res) {
                    layer.msg('数据返回错误', {icon: 2});
                }
            }).fail(function () {
                layer.msg('网络错误', {icon: 2});
            });
        });
    });
</script>
